<%@include file="../../generic/inc/head.jsp"%>

<!-- Import dojo -->
<%@include file="../../generic/inc/importdojo.jsp"%>

<%@ page import="fr.mywiki.view.web.struts.form.entry.EditEntryForm" %>
<%@ page import="fr.mywiki.view.array.ArrayPage" %>

<%
	String clientName = "editEntry.do";
	String formName = "editEntryForm";
	String modifDiv = "consultationRights";
	String modifDiv2 = "editionRights";
%>

<script>
<!--
<logic:equal value="<%=EditEntryForm.MODE_EDITION%>" property="mode" name="editEntryForm">
	startTimer();
</logic:equal>

function startTimer() {
  setTimeout("popAlert()",300000);
}

function popAlert() {
	alert("<bean:message key="entry.lock.warn" />");
}

function saveEntry() {
	document.forms["editEntryForm"].method.value='saveEntry';
	document.forms["editEntryForm"].submit();
}

function cancel() {
	document.forms["editEntryForm"].method.value='cancel';
	document.forms["editEntryForm"].submit();
}

function selectFile(fileName) {
	var myContent = document.forms["editEntryForm"].content.value;
	document.forms["editEntryForm"].content.value = myContent + 
			"{{" + fileName + "|" + fileName + "}}";
}

function toggleLayer(whichLayer) {
	if (document.getElementById) {
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = (style2.display=="none")? "block":"none";
	} else if (document.all) {
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = (style2.display=="none")? "block":"none";
	} else if (document.layers)	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = (style2.display=="none")? "block":"none";
	}
}

function openConsultationStructure() {
	// Loads the correct structure
	ajaxEngine.registerRequest('loadStructure','<%=clientName%>');
	ajaxEngine.registerAjaxElement('root');
	var var1 = new Date() ;
	var var2 = var1.getTime() ;
	ajaxEngine.sendRequest('loadStructure', "method=loadConsultationStructure","myTime="+var2);
			
	openStructurePopup();
}

function openEditionStructure() {
	// Loads the correct structure
	ajaxEngine.registerRequest('loadStructure','<%=clientName%>');
	ajaxEngine.registerAjaxElement('root');
	var var1 = new Date() ;
	var var2 = var1.getTime() ;
	ajaxEngine.sendRequest('loadStructure', "method=loadEditionStructure","myTime="+var2);

	openStructurePopup();
}

function openSelectModelPopup() {
	dijit.byId('dialogSelectModel').show();
}

function closeSelectModelPopup() {
	dijit.byId('dialogSelectModel').hide();
}
-->
</script>

<div id="mainPanel">
	<logic:equal value="true" property="displayMessage" name="editEntryForm">
		<bean:message key="entry.edit.oldVersion"/>
	</logic:equal>
	<p class="error">
		<html:errors bundle="ERROR_RESSOURCE_KEY"/>
	</p>

	<!-- File management -->
	<logic:equal value="true" property="manageFiles" name="editEntryForm">
		<p>
			<a href="javascript:toggleLayer('fileManagement');">
				<bean:message key="file.manage"/>
			</a>
		</p>
		<div id="fileManagement" style="display:none;">
			<%@include file="../../file/list/fileList.jsp"%>
		</div>
	</logic:equal>

	<html:form action="editEntry" >
		<html:hidden property="method" value="validate" />

		<logic:equal value="true" property="canSetRights" name="editEntryForm">
			<%@include file="../../generic/tree/multiTreeModalPopup.jsp"%>
		</logic:equal>

		<div id="mainLayer">

			<!-- Title -->			
			<p>
				<logic:equal value="<%=EditEntryForm.MODE_CREATION%>" property="mode" name="editEntryForm">
					<bean:message key="entry.title"/>:
					<html:text property="title" name="editEntryForm"/>
				</logic:equal>
				<logic:equal value="<%=EditEntryForm.MODE_EDITION%>" property="mode" name="editEntryForm">
					<h3><bean:write property="title" name="editEntryForm" /></h3>
				</logic:equal>
			</p>
			
			<!-- Access rights -->
			<logic:equal value="true" property="canSetRights" name="editEntryForm">
				<a href="javascript:openConsultationStructure();">
					<bean:message key="entry.edit.manageRights.consult"/>
				</a>&nbsp;
				<span id="consultationRights">
					<jsp:getProperty property="consultationRights" name="editEntryForm"/>
				</span>
				<br/>
				<a href="javascript:openEditionStructure();">
					<bean:message key="entry.edit.manageRights.edit"/>
				</a>&nbsp;
				<span id="editionRights">
					<jsp:getProperty property="editionRights" name="editEntryForm"/>
				</span>
			</logic:equal>
			
			<!-- Model selection -->
			<p>
				Model:&nbsp;
				<a href="#" onclick="javascript:openSelectModelPopup();">
					<bean:write property="selectedModel.name" name="editEntryForm"/>
				</a>
			</p>

			<!-- Model properties -->
			<%@include file="incEditProperties.jsp"%>
			
			<!-- Buttons -->
			<p>
				<a href="javascript:saveEntry();">
					<bean:message key="entry.save"/>
				</a>&nbsp;
				<a href="javascript:cancel()">
					<bean:message key="entry.cancel"/>
				</a>
			</p>
		</div>

<!-- Edition modal popup, name : dialogSelectModel  -->
<%@include file="popSelectModel.jsp"%>

	</html:form>
</div>

<%@include file="../../generic/inc/foot.jsp"%>
